package com.lyf.baoxian.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.lyf.baoxian.R;
import com.lyf.baoxian.adapter.MyGridViewAdapter;
import com.lyf.baoxian.adapter.SearchAdapter;
import com.lyf.baoxian.bean.SearchCustomer;
import com.lyf.baoxian.utils.MyMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 刘亚飞 on 2017/1/19.
 * 分类查询
 */

public class SelectActivity extends Activity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
    private RadioGroup rg_select;
    private RadioButton rb_zzy;
    private RadioButton rb_yzy;
    private GridView gridView;
    private MyGridViewAdapter adapter;

    //数据
    private List<String> datas1;
    private List<SearchCustomer> datas2;

    private ViewGroup title;
    private ListView lv_select;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);
        initView();
        initData();
    }

    private void initView() {
        rg_select = (RadioGroup) findViewById(R.id.rg_select);
        rb_zzy = (RadioButton) findViewById(R.id.rb_zzy);
        rb_yzy = (RadioButton) findViewById(R.id.rb_yzy);
        gridView = (GridView) findViewById(R.id.gridView);
        title = (ViewGroup) findViewById(R.id.lv_select_title);
        lv_select = (ListView) findViewById(R.id.lv_select);

        title.setBackgroundResource(R.color.home_tab);
        rg_select.check(R.id.rb_zzy);
        rg_select.setOnCheckedChangeListener(this);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                adapter.setSelection(i);
                adapter.notifyDataSetChanged();
            }
        });
    }

    private void initData() {
        MyMethod.setTitle(this, "分类查询", this);
        datas1 = new ArrayList<>();
        datas1.add("玉米保险");
        datas1.add("水稻保险");
        datas1.add("棉花保险");
        datas1.add("板栗保险");
        adapter = new MyGridViewAdapter(SelectActivity.this);
        adapter.setDatas(datas1);
        gridView.setAdapter(adapter);

        datas2 = new ArrayList<>();
        for (int i = 0; i < 40; i++) {
            datas2.add(new SearchCustomer("2016-12-31", "玉米保险", "张飒", "56¥"));
        }
        SearchAdapter adapter1 = new SearchAdapter(SelectActivity.this);
        adapter1.setDatas(datas2);
        lv_select.setAdapter(adapter1);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.every_top_img:
                Intent intent = new Intent(SelectActivity.this,SelectBaoXianActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i){
            case R.id.rb_zzy:
                rg_select.setBackgroundResource(R.drawable.left);
                break;
            case R.id.rb_yzy:
                rg_select.setBackgroundResource(R.drawable.right);
                break;
        }
    }
}
